%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Note this .m file reproduces Figure A4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;    % Clear the command window.
close all;  % Close all figures (except those of imtool.)
clear;  % Erase all existing variables. Or clearvars if you want.

x0=10;
y0=10;
width=850;
height=350;
set(gcf,'position',[x0,y0,width,height])
x = 15:-1:1;

y = [
0.518571429
0.298571429
0.261428571
0.258571429
0.097142857;
NaN
NaN
0.322857143
0.307142857
0.231428571;
NaN
NaN
0.388571429
NaN
NaN
]

h=barh(x,100*y,'EdgeColor','none')
box off
ax = gca;
ax.TickLength = [0 0]
xlabel('\color{black}Proportion of respondents, %','fontweight','bold')
ylabel('\color{black}Mechanisms recalled','fontweight','bold')
yticklabels({[],[],'\color{black}Due to the higher \pi, HP will increase','\color{black} \bf Other',[],...
    '\color{black}Developers reduce P due to lower demand',...
    '\color{black}Developers raise P to keep profit',...
    '\color{black}Developers reduce supply due to higher cost of borrowing',...
    '\color{black} \bf Supply side', []...
    '\color{black}HP declines due to higher discounting rate of CF',...
    '\color{black}Demand declines as banks make it harder to get loans',...
    '\color{black}Lower demand due to job losses and lower incomes',...
    '\color{black}Lower demand due to more savings',...
    '\color{black}Lower demand due to higher mortgage rate',...
    '\color{black} \bf Demand side'
    })
yticks(1:1:16)
xticklabels({'\color{black}0%','\color{black}10%','\color{black}20%','\color{black}30%','\color{black}40%','\color{black}50%','\color{black}60%','\color{black}70%','\color{black}16%','\color{black}18%','\color{black}20%'})
ylim([2 17])

set(gca,'box','off','FontSize',12);
set(gca,'ycolor','w','xcolor','w') 
ax.XGrid = 'on';
ax.GridColor = [0.1, 0.1, 0.1];
h.FaceColor = 'flat';
h.CData(15,:) = [1 0 0];
h.CData(14,:) = [1 0 0];
h.CData(13,:) = [1 0 0];
h.CData(12,:) = [1 0 0];
h.CData(11,:) = [1 0 0];

h.CData(8,:) = [0 0 1];
h.CData(7,:) = [0 0 1];
h.CData(6,:) = [0 0 1];
h.CData(3,:) = [0 1 1];
xtips1 = h(1).YEndPoints + 0.3;
ytips1 = h(1).XEndPoints;
labels1 = string(round(h(1).YData,2));
text(xtips1,ytips1,labels1,'VerticalAlignment','middle')


dpi = 100;
width_in = width / dpi;
height_in = height / dpi;

set(gcf, 'PaperUnits', 'inches');
set(gcf, 'PaperSize', [width_in, height_in]);
set(gcf, 'PaperPosition', [0, 0, width_in, height_in]);
set(gcf, 'PaperPositionMode', 'manual');
saveas(gcf,"Figure_A4.pdf",'pdf')







